package com.demo.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.demo.entity.Patient;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;
import java.util.List;

/**
 * 病患信息表 Mapper 接口
 *
 * @author zm
 * @since 2020-11-26
 */
public interface PatientMapper extends BaseMapper<Patient> {
    /**
     * 获取最小年份的第一个患者时间
     *
     * @return
     */
    Date getMinYear();

    /**
     * 获取最大年份的最后一个患者时间
     *
     * @return
     */
    Date getMaxYear();

    /**
     * 通过患者序列号ID，获取该患者所有vte防治评估ID
     *
     * @param patientId
     * @return
     */
    List<Integer> getVteIDByPatientId(@Param("patientId") Integer patientId);

    /**
     * 查询某月的内科患者
     *
     * @param startTime
     * @param endTime
     * @return
     */
    List<Integer> getPatientHeightAndInside(@Param("startTime") Date startTime, @Param("endTime") Date endTime, @Param("departments") List<Integer> departments);

    /**
     * 查询某月的外科患者
     *
     * @param startTime
     * @param endTime
     * @return
     */
    List<Integer> getPatientHeightAndOuter(@Param("startTime") Date startTime, @Param("endTime") Date endTime, @Param("departments") List<Integer> departments);

    /**
     * 获取某个时间段内的患者信息
     *
     * @param startTime
     * @param endTime
     * @return
     */
    List<Integer> getAppointTimePatient(@Param("startTime") Date startTime, @Param("endTime") Date endTime, @Param("departments") List<Integer> departments);

    /**
     * 通过患者ID集合，查询内外科各多少人
     *
     * @param patientId
     * @param deptType  内/外科
     * @return
     */
    List<Integer> getPatientDeptType(@Param("patientId") List<Integer> patientId, @Param("deptType") Integer deptType, @Param("departments") List<Integer> departments);

    /**
     * 获取当前住院患者总人数【在住院，且没有出院的】----全院
     *
     * @return
     */
    Integer getHospitalizedSum(Integer deptSn);

    /**
     * 获取某个时间患者总数
     *
     * @param startTime
     * @param endTime
     * @return
     */
    List<Integer> getMonthDatePatientSum(@Param("startTime") Date startTime, @Param("endTime") Date endTime);

    /***
     * 通过患者ID，获取患者详情
     * @param id
     * @return
     */
    Patient getDetailsById(@Param("id") Integer id);

    List<Patient> patientList(@Param("pageNumber") Integer pageNumber,
                              @Param("pageSize") Integer pageSize,
                              @Param("admissionId") String admissionId,
                              @Param("deptType") Integer deptType,
                              @Param("patientId") String patientId,
                              @Param("vestType") Integer vestType,
                              @Param("status") Integer status,
                              @Param("deptSn") Integer deptSn,
                              @Param("workId") String workId,
                              @Param("wardIdArray") List<Integer> wardIdArray);

    Integer patientListCount(@Param("admissionId") String admissionId,
                             @Param("deptType") Integer deptType,
                             @Param("patientId") String patientId,
                             @Param("vestType") Integer vestType,
                             @Param("status") Integer status,
                             @Param("deptSn") Integer deptSn,
                             @Param("workId") String workId,
                             @Param("wardIdArray") List<Integer> wardIdArray);


    List<Integer> vteDepartmentMonitoring(@Param("deptSn") Integer deptSn);

    Integer getAllPatientCount(@Param("departments") List<Integer> paramList, @Param("startTime") Date paramDate1, @Param("endTime") Date paramDate2);

    boolean updateByHisPatientId(@Param("hisPatientId") Integer hisPatientId,
                                 @Param("status") Integer status,
                                 @Param("admissionId") String admissionId,
                                 @Param("wardId") Integer wardId,
                                 @Param("bedId") String bedId,
                                 @Param("medicalLeader") Integer medicalLeader,
                                 @Param("medicalLeaderName") String medicalLeaderName,
                                 @Param("doctorInCharge") Integer doctorInCharge,
                                 @Param("doctorInChargeName") String doctorInChargeName,
                                 @Param("headNurse") Integer headNurse,
                                 @Param("headNurseName") String headNurseName,
                                 @Param("nurseInCharge") Integer nurseInCharge,
                                 @Param("nurseInChargeName") String nurseInChargeName,
                                 @Param("hospitalDisttrictName") String hospitalDisttrictName,
                                 @Param("hospitalDisttrictId") Integer hospitalDisttrictId,
                                 @Param("deptType") Integer deptType,
                                 @Param("deptName") String deptName,
                                 @Param("deptSn") Integer deptSn,
                                 @Param("wardName") String wardName);

    @Update("update pd_patient set status=#{status}, updated_time=now() where his_patient_id = #{hisPatientId}")
    boolean updateStatus(@Param("status") Integer status, @Param("hisPatientId") Integer hisPatientId);

    @Select("select * from pd_patient where deleted_time is null and status != 4 and dept_sn=#{deptSn}")
    List<Patient> selectByDeptSn(@Param("deptSn") Integer deptSn);

    @Select("select * from pd_patient where deleted_time is null and status != 4")
    List<Patient> selectInHospitalPatients();

    @Select("select * from pd_patient where deleted_time is null and patient_id=#{patientId}")
    Patient queryValidPatient(@Param("patientId") Integer patientId);

    @Select("select * from pd_patient where his_patient_id=#{hisPatientId}")
    Patient queryByHisPatientId(@Param("hisPatientId") Integer hisPatientId);
}
